package com.hbvtc.xxxy.nikeSale.frames;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.hbvtc.xxxy.nikeSale.daos.Vipdao;
import com.hbvtc.xxxy.nikeSale.models.Vips;

public class SelectVipNike extends JFrame {
	Connection conn;
	PreparedStatement pre;
	String sql;
	JLabel jLabel1, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7;
	JTextField jTextField;
	JButton jButton1;
	ResultSet rSet;
	JPanel jPanel=new JPanel();
	Vips vips = new Vips();
	Vipdao vipdao = new Vipdao();

	public SelectVipNike() {
		this.setTitle("会员查询界面");
		this.setSize(1000, 700);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		// 设置标题栏的图标
		ImageIcon imageIcon = new ImageIcon(getClass().getResource("01.png"));
		this.setIconImage(imageIcon.getImage());
		// 背景图片的路径
		String path = "images/001.jpg";
		ImageIcon background = new ImageIcon(path);
		// 把背景图片显示在一个标签里面
		JLabel label = new JLabel(background);
		// 把标签的大小位置设置为图片刚好填充整个面板
		label.setBounds(0, 0, this.getWidth(), this.getHeight());
		// 把内容窗格转化为JPanel，否则不能用方法setOpaque()来使内容窗格透明
		JPanel imagePanel = (JPanel) this.getContentPane();
		imagePanel.setOpaque(false);
		// 把背景图片添加到分层窗格的最底层作为背景
		this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));

		jLabel1 = new JLabel("请输入会员id:");
		jLabel2 = new JLabel("会员姓名：");
		jLabel3 = new JLabel("会员余额：");
		jLabel4 = new JLabel("会员积分：");

		jTextField = new JTextField();
		setContentPane(jPanel);
		jPanel.setLayout(null);
		
		jPanel.add(jLabel1);
		jPanel.add(jLabel2);
		jPanel.add(jLabel3);
		jPanel.add(jLabel4);
		jPanel.add(jTextField);
		jButton1 = new JButton("立即查询");
		jPanel.add(jButton1);

		jLabel1.setBounds(150, 100, 180, 30);
		jLabel1.setFont(new Font(null, 0, 24));
		jLabel2.setBounds(150, 200, 180, 30);
		jLabel2.setFont(new Font(null, 0, 24));
		jLabel3.setBounds(150, 300, 180, 30);
		jLabel3.setFont(new Font(null, 0, 24));
		jLabel4.setBounds(150, 400, 180, 30);
		jLabel4.setFont(new Font(null, 0, 24));

		jTextField.setBounds(400, 100, 250, 30);
		jTextField.setFont(new Font(null, 0, 24));
		jButton1.setBounds(600, 550, 150, 40);
		jButton1.setFont(new Font(null, 0, 24));

		jButton1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				try {
					if (vipdao.sss(jTextField.getText()) == true) {
						vips = null;
						vips = vipdao.select(jTextField.getText());
						Huiyuan1(vips);
					} else {
						JOptionPane.showMessageDialog(SelectVipNike.this,
								"会员里面没有这个id");
					}
				} catch (NumberFormatException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}

			private void Huiyuan1(Vips vips) {
				// TODO Auto-generated method stub

				jLabel5 = new JLabel();
				jLabel5.setText(vips.getName());
				jLabel6 = new JLabel();
				jLabel6.setText("" + vips.getBalance());
				jLabel7 = new JLabel();
				jLabel7.setText("" + vips.getIntegration()+"元");
				jPanel.add(jLabel5);
				jPanel.add(jLabel6);
				jPanel.add(jLabel7);
				jLabel5.setBounds(400, 200, 250, 30);
				jLabel5.setFont(new Font(null, 0, 24));
				jLabel6.setBounds(400, 300, 250, 30);
				jLabel6.setFont(new Font(null, 0, 24));
				jLabel7.setBounds(400, 400, 250, 30);
				jLabel7.setFont(new Font(null, 0, 24));
			}
		});
	}

	public static void main(String[] args) {
		new SelectVipNike().setVisible(true);
	}
}
